package com.example.myblog.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.myblog.service.*;
import com.example.myblog.shiro.AccountProfile;
import org.apache.shiro.SecurityUtils;
import org.modelmapper.ModelMapper;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;

@Controller
public class BaseController {

    @Autowired
    HttpServletRequest request;
    @Autowired
    MPostService postService;
    @Autowired
    MCommentService commentService;
    @Autowired
    MUserService userService;
    @Autowired
    MUserMessageService messageService;
    @Autowired
    MUserCollectionService collectionService;
    @Autowired
    MCategoryService categoryService;
    @Autowired
    WsService wsService;
    @Autowired
    SearchService searchService;
    @Autowired
    AmqpTemplate amqpTemplate;
    @Autowired
    ChatService chatService;


    /**
     * 分页信息
     * @return
     */
    public Page getPage(){
        int pn = ServletRequestUtils.getIntParameter(request, "pn", 1);
        int size = ServletRequestUtils.getIntParameter(request, "size", 2);
        Page page = new Page(pn,size);
        return page;
    }

    /**
     * 获取登录用户的信息
     * @return
     */
    protected AccountProfile getProfile() {
        return (AccountProfile) SecurityUtils.getSubject().getPrincipal();
    }

    /**
     * 获取登录用户的id
     * @return
     */
    protected Long getProfileId() {
        return getProfile().getId();
    }
}
